<html>
<head>
  <title>TestCollatz.py</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#444444">#!/usr/bin/env python</font>

<font color="#444444"># --------------------------------------</font>
<font color="#444444"># projects/python/collatz/TestCollatz.py</font>
<font color="#444444"># Copyright (C) 2009</font>
<font color="#444444"># Glenn P. Downing</font>
<font color="#444444"># --------------------------------------</font>

<font color="#444444"># To run the tests</font>
<font color="#444444">#     TestCollatz.py</font>

<font color="#444444"># To document the tests</font>
<font color="#444444">#     pydoc -w TestCollatz</font>

<strong>import</strong> <font color="#2040a0">main</font>
<strong>import</strong> <font color="#2040a0">unittest</font>

<font color="#444444"># ----------</font>
<font color="#444444"># TestReader</font>
<font color="#444444"># ----------</font>

<strong>class</strong> <font color="#2040a0">TestReader</font> <font color="4444FF">(</font><font color="#2040a0">object</font><font color="4444FF">)</font> <font color="4444FF">:</font>
<strong>   <font color="ff0000"> def</font><font color="ff0000"> __init__</font> <font color="2040a0">(self, s)</font> :
</strong>        <font color="#2040a0">self</font>.<font color="#2040a0">s</font> <font color="4444FF">=</font> <font color="#2040a0">s</font>

<strong>   <font color="ff0000"> def</font><font color="ff0000"> read</font> <font color="2040a0">(self)</font> :
</strong>        <strong>return</strong> <font color="#2040a0">self</font>.<font color="#2040a0">s</font>

<font color="#444444"># ----------</font>
<font color="#444444"># TestWriter</font>
<font color="#444444"># ----------</font>

<strong>class</strong> <font color="#2040a0">TestWriter</font> <font color="4444FF">(</font><font color="#2040a0">object</font><font color="4444FF">)</font> <font color="4444FF">:</font>
<strong>   <font color="ff0000"> def</font><font color="ff0000"> str</font> <font color="2040a0">(self)</font> :
</strong>        <strong>return</strong> <font color="#2040a0">self</font>.<font color="#2040a0">s</font>

<strong>   <font color="ff0000"> def</font><font color="ff0000"> write</font> <font color="2040a0">(self, *a)</font> :
</strong>        <font color="#2040a0">self</font>.<font color="#2040a0">s</font> <font color="4444FF">=</font> <font color="#2040a0">str</font><font color="4444FF">(</font><font color="#2040a0">a</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">)</font>
        <strong>for</strong> <font color="#2040a0">w</font> <strong>in</strong> <font color="#2040a0">a</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">:</font><font color="4444FF">]</font> <font color="4444FF">:</font>
            <font color="#2040a0">self</font>.<font color="#2040a0">s</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#008000">' '</font>
            <font color="#2040a0">self</font>.<font color="#2040a0">s</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#2040a0">str</font><font color="4444FF">(</font><font color="#2040a0">w</font><font color="4444FF">)</font>
        <font color="#2040a0">self</font>.<font color="#2040a0">s</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#008000">'\n'</font>

<font color="#444444"># -----------</font>
<font color="#444444"># TestCollatz</font>
<font color="#444444"># -----------</font>

<strong>class</strong> <font color="#2040a0">TestCollatz</font> <font color="4444FF">(</font><font color="#2040a0">unittest</font>.<font color="#2040a0">TestCase</font><font color="4444FF">)</font> <font color="4444FF">:</font>
    <font color="#444444"># ----</font>
    <font color="#444444"># read</font>
    <font color="#444444"># ----</font>

<strong>   <font color="ff0000"> def</font><font color="ff0000"> test_read</font> <font color="2040a0">(self)</font> :
</strong>        <font color="#2040a0">reader</font> <font color="4444FF">=</font> <font color="#2040a0">TestReader</font><font color="4444FF">(</font><font color="#008000">'1 10\n'</font><font color="4444FF">)</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">my_read</font><font color="4444FF">(</font><font color="#2040a0">reader</font><font color="4444FF">)</font>
        <font color="#2040a0">self</font>.<font color="#2040a0">assert_</font><font color="4444FF">(</font><font color="#2040a0">main</font>.<font color="#2040a0">i</font> <font color="4444FF">=</font><font color="4444FF">=</font>  <font color="#FF0000">1</font><font color="4444FF">)</font>
        <font color="#2040a0">self</font>.<font color="#2040a0">assert_</font><font color="4444FF">(</font><font color="#2040a0">main</font>.<font color="#2040a0">j</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">10</font><font color="4444FF">)</font>

    <font color="#444444"># ----</font>
    <font color="#444444"># eval</font>
    <font color="#444444"># ----</font>

<strong>   <font color="ff0000"> def</font><font color="ff0000"> test_eval1</font> <font color="2040a0">(self)</font> :
</strong>        <font color="#2040a0">main</font>.<font color="#2040a0">i</font> <font color="4444FF">=</font>  <font color="#FF0000">1</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#FF0000">10</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font>  <font color="#FF0000">0</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">my_eval</font><font color="4444FF">(</font><font color="4444FF">)</font>
        <font color="#2040a0">self</font>.<font color="#2040a0">assert_</font><font color="4444FF">(</font><font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">20</font><font color="4444FF">)</font>

<strong>   <font color="ff0000"> def</font><font color="ff0000"> test_eval2</font> <font color="2040a0">(self)</font> :
</strong>        <font color="#2040a0">main</font>.<font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">100</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#FF0000">200</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font>   <font color="#FF0000">0</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">my_eval</font><font color="4444FF">(</font><font color="4444FF">)</font>
        <font color="#2040a0">self</font>.<font color="#2040a0">assert_</font><font color="4444FF">(</font><font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">125</font><font color="4444FF">)</font>

<strong>   <font color="ff0000"> def</font><font color="ff0000"> test_eval3</font> <font color="2040a0">(self)</font> :
</strong>        <font color="#2040a0">main</font>.<font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">201</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#FF0000">210</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font>   <font color="#FF0000">0</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">my_eval</font><font color="4444FF">(</font><font color="4444FF">)</font>
        <font color="#2040a0">self</font>.<font color="#2040a0">assert_</font><font color="4444FF">(</font><font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">89</font><font color="4444FF">)</font>

<strong>   <font color="ff0000"> def</font><font color="ff0000"> test_eval4</font> <font color="2040a0">(self)</font> :
</strong>        <font color="#2040a0">main</font>.<font color="#2040a0">i</font> <font color="4444FF">=</font>  <font color="#FF0000">900</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#FF0000">1000</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font>    <font color="#FF0000">0</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">my_eval</font><font color="4444FF">(</font><font color="4444FF">)</font>
        <font color="#2040a0">self</font>.<font color="#2040a0">assert_</font><font color="4444FF">(</font><font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">174</font><font color="4444FF">)</font>

    <font color="#444444"># -----</font>
    <font color="#444444"># print</font>
    <font color="#444444"># -----</font>

<strong>   <font color="ff0000"> def</font><font color="ff0000"> test_print</font> <font color="2040a0">(self)</font> :
</strong>        <font color="#2040a0">main</font>.<font color="#2040a0">i</font> <font color="4444FF">=</font>  <font color="#FF0000">1</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">j</font> <font color="4444FF">=</font> <font color="#FF0000">10</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">v</font> <font color="4444FF">=</font> <font color="#FF0000">20</font>
        <font color="#2040a0">writer</font> <font color="4444FF">=</font> <font color="#2040a0">TestWriter</font><font color="4444FF">(</font><font color="4444FF">)</font>
        <font color="#2040a0">main</font>.<font color="#2040a0">my_print</font><font color="4444FF">(</font><font color="#2040a0">writer</font><font color="4444FF">)</font>
        <font color="#2040a0">self</font>.<font color="#2040a0">assert_</font><font color="4444FF">(</font><font color="#2040a0">writer</font>.<font color="#2040a0">str</font><font color="4444FF">(</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#008000">'1 10 20\n'</font><font color="4444FF">)</font>

<strong>if</strong> <font color="#2040a0">__name__</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#008000">&quot;__main__&quot;</font> <font color="4444FF">:</font>
    <font color="#2040a0">unittest</font>.<font color="#2040a0">main</font><font color="4444FF">(</font><font color="4444FF">)</font>

</pre>
<hr>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1
</body>
</html>
